package com.xt.tea.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xt.tea.constant.ApiConstant;
import com.xt.tea.entity.bo.OptionBo;
import com.xt.tea.entity.bo.RequestResult;
import com.xt.tea.entity.bo.UserBo;
import com.xt.tea.entity.domain.User;
import com.xt.tea.entity.vo.Condition;
import com.xt.tea.entity.vo.user.LoginVo;
import com.xt.tea.entity.vo.user.RegisterVo;
import com.xt.tea.entity.vo.user.UserVo;
import com.xt.tea.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("用户相关")
@RestController
@RequestMapping(ApiConstant.API_V1+"user")
@AllArgsConstructor
public class UserController {

    private final UserService userService;
    @ApiOperation("用户登录")
    @PostMapping("/login")
    public RequestResult<String> userLogin(@RequestBody LoginVo loginVo){
        return RequestResult.success(userService.userLogin(loginVo));
    }
    @ApiOperation("用户注册")
    @PostMapping("/register")
    public RequestResult<Integer> userRegister(@RequestBody RegisterVo registerVo){
        return RequestResult.success(userService.userRegister(registerVo));
    }
    @ApiOperation("获取用户信息（分页）")
    @PostMapping("/getUserInfo")
    public RequestResult<IPage<UserBo>> getUserInfo(@RequestBody Condition<UserVo> userCondition){
        return RequestResult.success(userService.getUserInfo(userCondition));
    }
    @ApiOperation("获取用户信息（根据ID）")
    @GetMapping("/getUserInfoById")
    public RequestResult<User> getUserInfoById(Integer id){
        return RequestResult.success(userService.getUserInfoById(id));
    }

    @ApiOperation("获取用户信息（根据token）")
    @GetMapping("/getUserInfoByToken")
    public RequestResult<User> getUserInfoByToken(String token){
        return RequestResult.success(userService.getUserInfoByToken(token));
    }
    @ApiOperation("更新用户信息")
    @PutMapping("/updateUser")
    public RequestResult<UserBo> updateUser(@RequestBody UserVo user){
        return RequestResult.success(userService.updateUserInfo(user));
    }
    @ApiOperation("更新用户状态")
    @GetMapping("/updateUserStatus")
    public RequestResult<UserBo> updateUserStatus(Integer id){
        return RequestResult.success(userService.updateUserStatus(new User(id)));
    }
    @ApiOperation("删除用户信息")
    @GetMapping("/deleteUser")
    public RequestResult<Integer> deleteUser(Integer id){
        return RequestResult.success(userService.deleteUser(new User(id)));
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getUserByName")
    public RequestResult<List<OptionBo>> getUserByName(String name){
        return RequestResult.success(userService.getUserByName(name));
    }

    @ApiOperation("充值密码")
    @GetMapping("/resetPassword")
    public RequestResult<Boolean> resetPassword(String id,String password){
        return RequestResult.success(userService.resetPassword(id,password));
    }


}
